static inline max_heapify(int *data, int start, int end)
{
	int dad = start;
	int son = dad*2 + 1;
	int temp;

	while (son <= end)
	{
		if ( (son + 1 <= end) && (data[son+1] > data[son]) )
		{
			son++;
		}
		if (data[dad] < data[son])
		{
			temp = data[son];
			data[son] = data[dad];
			data[dad] = temp;
		}
		dad = son;
		son = dad*2 + 1;
	}
	
}


int heap_sort(int *data, int data_lenth)
{
	if (data == 0 || data_lenth <= 0)
	{
		return -1;
	}

	int i;
	int temp;

	//从最后一个父节点开始调整
	for (i = data_lenth/2 -1;i >= 0; i--)
	{
		max_heapify(data, i, data_lenth-1);
	}

	for (i = data_lenth - 1; i > 0; i--)
	{
		temp = data[i];
		data[i] = data[0];
		data[0] = temp;

		max_heapify(data, 0, i - 1);	
	}
	return 0;

}
